#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#include "ppport.h"


MODULE = foo		PACKAGE = foo::scalar

SV *
new(c,i)
	const char* c
	int i
CODE:
    SV *retval = newSV(0);
    sv_setiv(retval, i);
    RETVAL = sv_bless(newRV_noinc(retval), gv_stashpv(c, 0));
OUTPUT:
	RETVAL

int
val(r)
	SV* r
CODE:
	RETVAL = SvIV((SV*)SvRV(r));
OUTPUT:
	RETVAL


MODULE = foo		PACKAGE = foo::hash

SV *
new(c,i)
	const char* c
	int i
CODE:
	HV *hv = newHV();
    SV *retval = newSV(0);
    sv_setiv(retval, i);
	hv_store(hv, "val", 3, retval, 0);
    RETVAL = sv_bless(newRV_noinc((SV*)hv), gv_stashpv(c, 0));
OUTPUT:
	RETVAL

int
val(sv)
	SV* sv
CODE:
	HV *hv = (HV*)SvRV(sv);
	SV** ssv = hv_fetch(hv, "val", 3, 0); 
	RETVAL = SvIV((SV*)*ssv);
OUTPUT:
	RETVAL


MODULE = foo		PACKAGE = foo::array

SV *
new(c,i)
	const char* c
	int i
CODE:
	AV *av = newAV();
    SV *retval = newSV(0);
    sv_setiv(retval, i);
	av_store(av, 0, retval);
    RETVAL = sv_bless(newRV_noinc((SV*)av), gv_stashpv(c, 0));
OUTPUT:
	RETVAL

int
val(sv)
	SV* sv
CODE:
	AV *av = (AV*)SvRV(sv);
	SV** ssv = av_fetch(av, 0, 0); 
	RETVAL = SvIV((SV*)*ssv);
OUTPUT:
	RETVAL
